﻿using System;
using System.Linq;
using System.Web.Security;
using NStore.Infrastructure.Repositories;

namespace NStore.Infrastructure.Security
{
    public class NStoreRoleProvider : RoleProvider
    {
        private readonly UserRepository _userRepository;
        public NStoreRoleProvider() : this(new UserRepository()) { }
        public NStoreRoleProvider(UserRepository repository)
        {
            _userRepository = repository;
        }

        public override string[] GetRolesForUser(string username)
        {
            if (String.IsNullOrEmpty(username)) return new string[0];
            return _userRepository.GetByUserName(username).Roles.ToArray();
        }

        #region "NotImplementedException"
        public override bool IsUserInRole(string username, string roleName)
        {
            throw new NotImplementedException();
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }

        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName { get; set; }
        #endregion
    }
}
